import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../../provide/cart.dart';
import '../../provide/details_info.dart';
import '../../provide/CurrentIndex.dart';

class DetailsBottom extends StatelessWidget {
  const DetailsBottom({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    var goodInfo = Provide.value<DetailsInfoProvide>(context).goodsinfo.data.goodInfo;
    String goodsId = goodInfo.goodsId;
    String goodsName = goodInfo.goodsName;
    double price = goodInfo.oriPrice;
    int count = 1;
    String images = goodInfo.image1;

    return Container(
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(90),
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Stack(
            children: <Widget>[
              InkWell(
                onTap: (){
                  Provide.value<CurrentIndexProvide>(context).changeIndex(2);
                  Navigator.pop(context);
                },
                child: Container(
                  width: ScreenUtil().setWidth(110),
                  alignment: Alignment.center,
                  child: Icon(Icons.shopping_cart,size:30,color:Colors.red),
                ),
              ),
              Provide<CartProvide>(
                builder: (context,childwidget,childProvide){
                  return Positioned(
                    top:3,
                    right:10 ,
                    child: Container(
                      padding: EdgeInsets.fromLTRB(6, 3, 6, 3),
                      decoration: BoxDecoration(
                        color: Colors.pink,
                        border: Border.all(width: 2,color:Colors.white),
                        borderRadius: BorderRadius.circular(12.0)
                      ),
                      child: Text(
                        '${childProvide.allGoodCount}',
                        style: TextStyle(
                          color:Colors.white,
                          fontSize: ScreenUtil().setSp(18.0),
                        ),
                      ),
                    ),
                  );
                },
              )
            ],
          ),

          InkWell(
            onTap: ()async{
                await Provide.value<CartProvide>(context).save(goodsId, goodsName, count, price, images);
            },
            child: Container(
              width: ScreenUtil().setWidth(320),
              alignment: Alignment.center,
              color: Colors.green,
              child: Text('加入购物车',style: TextStyle(fontSize:ScreenUtil().setSp(28.0),color:Colors.white)),
            ),
          ),
          InkWell(
            onTap: ()async{
                await Provide.value<CartProvide>(context).remove();
            },
            child: Container(
              width: ScreenUtil().setWidth(320),
              alignment: Alignment.center,
              color: Colors.red,
              child: Text('立即购买',style: TextStyle(fontSize:ScreenUtil().setSp(28.0),color:Colors.white)),
            ),
          )
        ],
      ),
    );
  }
}
